package com.blogs.component;

import java.util.ArrayList;

import com.blogs.entity.CommentFeed;
import com.blogs.tools.DBSharedPreferences;
import com.blogs.tools.FormatTime;
import com.blogs.tools.HtmlFormat;
import com.cnblogs.R;
import com.cnblogs.R.color;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CommentAdapter extends BaseAdapter{
	private  ArrayList<CommentFeed> feedList = null;
	private ViewHolder holder;
	private Activity context = null;
	private DBSharedPreferences sp;
	public CommentAdapter(Activity context, ArrayList<CommentFeed> feedList)
	{
		this.context = context;
		this.feedList = feedList;
		sp= new DBSharedPreferences(context);
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return feedList.size();
	}
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return feedList.get(position);
	}
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null ) {
			convertView = View.inflate(context, R.layout.comment_adapter_template,null);
			holder=new ViewHolder();
			holder.comment_floor=(TextView)convertView.findViewById(R.id.comment_floor);
			holder.comment_user_name=(TextView)convertView.findViewById(R.id.comment_user_name);
			holder.comment_content=(TextView)convertView.findViewById(R.id.comment_content);
			holder.comment_time=(TextView)convertView.findViewById(R.id.comment_time);
			convertView.setTag(holder);
		}
	    else
	    {
	    	holder = (ViewHolder) convertView.getTag();
	    }
		holder.comment_floor.setText((position+1)+"楼");
		holder.comment_user_name.setText(feedList.get(position).author);
		Log.i("comment_content", feedList.get(position).content);
		holder.comment_content.setText(HtmlFormat.ReplaceAt(feedList.get(position).content));
		holder.comment_time.setText(FormatTime.formatLong(feedList.get(position).comment_time));
		if(sp.GetIsDarkState())
		{
			holder.comment_content.getBackground().setLevel(2);
			holder.comment_user_name.setTextColor(context.getResources().getColor(color.con_text_night));
		}
		else
		{
			holder.comment_content.getBackground().setLevel(1);
			holder.comment_user_name.setTextColor(context.getResources().getColor(color.con_text_light));
		}
		Log.i("ListView_position", position+"");
		return convertView;
	}
	class ViewHolder 
	{
		TextView comment_floor;
		TextView comment_user_name;
		TextView comment_content;
		TextView comment_time;
	}
}
